using QFramework;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AddressableAssets;
using Cysharp.Threading.Tasks;

public interface IWmsSystem : ISystem
{
    void InitializeCargo(Action OnInit);
}

public class WmsSystem : AbstractSystem, IWmsSystem
{
    //private float defaultShelfSpace = 0.090f;
    public async void InitializeCargo(Action OnInit)
    {
        this.GetModel<IGameModel>().CargoPrefab = await Addressables.LoadAssetAsync<GameObject>(AddressableKey.cargoContainerPrefab);
        this.GetModel<IGameModel>().Cargo_1200_1200_1050_Prefab = await Addressables.LoadAssetAsync<GameObject>(AddressableKey.Cargo_1100_1100_1400_Prefab);

        PoolsInGame.CargoContainers.SetPrefab(this.GetModel<IGameModel>().CargoPrefab.transform);
        PoolsInGame.Cargo_1100_1100_1400s.SetPrefab(this.GetModel<IGameModel>().Cargo_1200_1200_1050_Prefab.transform);

        OnInit?.Invoke();
    }

    /*public void InitShelfGroup(List<ShelfgroupProperty> shelfGroupProps)
    {
        InsertShelvesToShelfGroup(shelfGroupProps);
        //StoreShelfRows(shelfGroups);
    }

    private void InsertShelvesToShelfGroup(List<ShelfgroupProperty> ShelfProperties)
    {
        foreach (var shelfProp in ShelfProperties)
        {
            List<float> heights = new List<float>();
            if (shelfProp.type == ShelfgroupProperty.ShelfType.Normal)
            {
                heights.Add(0);
                heights.Add(1.5f);
            }
            else
            {
                heights.Add(0);
                heights.Add(1.935f);
                heights.Add(1.935f + 1.650f);
                heights.Add(1.935f + 1.650f + 1.650f);
            }
            Shelfgroup shelfGroup = new(shelfProp, defaultShelfSpace, heights);
            this.GetModel<IShelfModel>().shelves.Add(shelfGroup);
        }
    }*/

    private void StoreShelfRows(List<Shelfgroup> rows_of_Shelves)
    {
        foreach (var row in rows_of_Shelves)
        {
            try
            {
                this.GetModel<IShelfModel>().shelves.Add(row);
            }
            catch (Exception ex)
            {
                Debug.LogError(ex);
            }
        }
    }

    protected override void OnInit()
    {

    }
}